﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using DAL;


namespace BUL
{
    public class PageBul
    {
        private PageDal db = new PageDal();
        #region[Page_GetById]
        public  List<Page> Page_GetById(string Id)
        {
            return db.Page_GetById(Id);
        }
        #endregion
        #region[Page_GetByLink]
        public  List<Page> Page_GetByLink(string link)
        {
            return db.Page_GetByLink(link);
        }
        #endregion
        #region[Page_GetBySub]
        public  List<Page> Page_GetBySub(string Level)
        {
            return db.Page_GetBySub(Level);
        }
        #endregion
        #region[Page_GetByCungCap]
        public  List<Page> Page_GetByCungCap(string Level)
        {
            return db.Page_GetByCungCap(Level);
        }
        #endregion
        #region[Page_GetByTop]
        public  List<Page> Page_GetByTop(string Top, string Where, string Order)
        {
            return db.Page_GetByTop(Top, Where, Order);
        }
        #endregion
        #region[Page_GetByAll]
        public  List<Page> Page_GetByAll(string Lang)
        {
            return db.Page_GetByAll(Lang);
        }
        #endregion
        #region[Page_GetByLink]
        public  List<Page> Page_GetByLink(string Link, string Lang)
        {
            List<Page> list = new List<Page>();
            list = db.Page_GetByAll(Lang);
            return list.FindAll(delegate(Page obj)
            {
                return obj.Link.ToLower() == Link;
            });
        }
        public  string Page_GetLevelByURL(string URL, string Lang)
        {
            string strReturn = "";
            List<Page> list = Page_GetByLink(URL, Lang);
            if (list.Count > 0)
            {
                strReturn = list[0].Level;
            }
            return strReturn;
        }
        public  string Page_GetLevelByURL(string URL, string Lang, string GroupNewsId)
        {
            string strReturn = "";
            List<Page> lst = new List<Page>();
            List<Page> list = db.Page_GetByAll(Lang);
            lst = list.FindAll(delegate(Page obj)
            {
                return obj.Link.ToLower().Contains("/news/" + GroupNewsId);
            });
            if (lst.Count > 0)
            {
                strReturn = lst[0].Level;
            }
            return strReturn;
        }
        #endregion
        #region[Page_GetByPosition]
        //public  List<Page> Page_GetByPosition(string position, string Lang)
        //{
        //    return Page_GetByPosition(position, Lang, 0);
        //}
        public  List<Page> Page_GetByPosition(string position, string Lang, int LevelLength)
        {
            List<Page> list = new List<Page>();
            list = db.Page_GetByAll(Lang);
            return list.FindAll(obj =>
                                    {
                                        if (LevelLength > 0)
                                        {
                                            return obj.Position == position && obj.Level.Length == LevelLength;
                                        }
                                        return obj.Position == position;
                                    });
        }
        public  List<Page> Page_GetByPositionLeght5(string lang)
        {
            List<Page> list = new List<Page>();
            list = db.Page_GetByAll(lang);
            return list.FindAll(obj => obj.Level.Length == 5);
            //return list.FindAll(delegate(Page obj)
            //{
            //    return obj.Level.Length == 5;
            //});
        }
        #endregion
        #region[Page_GetByLevel]
        //public  List<Page> Page_GetByLevel(string Level, string Lang)
        //{
        //    return Page_GetByLevel(Level, Lang, 0);
        //}
        public  List<Page> Page_GetByLevel(string Level, string Lang, int LevelLength)
        {
            return db.Page_GetByLevel(Level, Lang, LevelLength);
        }
        #endregion
        #region[Page_Paging]
        public  List<Page> Page_Paging(string CurentPage, string PageSize, string Lang)
        {
            return db.Page_Paging(CurentPage, PageSize, Lang);
        }
        #endregion
        #region[Page_Insert]
        public  bool Page_Insert(Page data)
        {
            return db.Page_Insert(data);
        }
        #endregion
        #region[Page_Update]
        public  bool Page_Update(Page data)
        {
            return db.Page_Update(data);
        }
        #endregion
        #region[Page_Delete]
        public  bool Page_Delete(string Id)
        {
            return db.Page_Delete(Id);
        }
        #endregion
    }
}
